package models

import (
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(30);not null;comment:商品标题"`
	Image  string  `gorm:"type:varchar(200);not null;comment:商品图片"`
	Price  float64 `gorm:"type:decimal(10,2);not null;comment:商品价格"`
	Num    int     `gorm:"type:int(11);not null;comment:商品数量"`
	Status int     `gorm:"type:int;not null;default:1;comment:0未上架 1上架"`
}

func (g *Goods) Create() error {
	return DB.Debug().Create(&g).Error
}
func (g *Goods) FindGoodsById() error {
	return DB.Debug().Where("id = ?", g.ID).First(&g).Error
}
func (g *Goods) ListGoods() (goodsList []*Goods, err error) {
	err = DB.Debug().Find(&goodsList).Error
	return
}
